FROM golang:1.16.8 AS builder

ENV GO111MODULE=on \
    GOPROXY=https://goproxy.cn,direct

WORKDIR /goproject/src/httpserver

COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .

RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build  -o main .

FROM alpine:3.10 AS final

RUN mkdir  /httpserver
WORKDIR /httpserver
COPY --from=builder /goproject/src/httpserver/main /httpserver/
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

EXPOSE 80

ENTRYPOINT ["/httpserver/main"]


